package test.dao;


import java.util.List;
import java.util.Map;

import test.bean.UserBean;
import test.util.JDBCUtil;
import test.util.StringUtil;

public class LoginDao {
	public boolean logDao(UserBean ub){
		String sql="select*from user where username='"+
			       ub.getUserName()+"'and password='"+ub.getPassWord()+"'";
		List<Map<String,Object>> result =JDBCUtil.doQuery(sql);
		if(result !=null&&result.size()==1){
			return true;
		}else{
			return false;
		}
	}
	public boolean signUsDao(UserBean ub){
		String sql="select*from user where username='"+ub.getUserName()+"'";
		List<Map<String,Object>> result =JDBCUtil.doQuery(sql);
		if(result ==null){
			return true;
		}else{
			return false;
		}
		
	}
	public boolean insertUser(UserBean ub){
		String userName =ub.getUserName();
		String passWord =ub.getPassWord();
		if(!StringUtil.isEmpty(userName)&&!StringUtil.isEmpty(passWord)){
		return false;
		}else{
			String sql="select*from user where username='"+ub.getUserName()+"'";
			List<Map<String,Object>> result = JDBCUtil.doQuery(sql);
		if(result != null && result.size() >= 1){
				return false;		
		}else{
	    String sql1 = "insert into user(username,password) values('"+userName+"','"+passWord+"')" ;
 
	    return JDBCUtil.doUpdate(sql1);
		}
		}
	}

}
